package com.ruoyi.washer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.washer.model.DivideAccountsQueryByMonthReq;
import com.ruoyi.washer.model.DivideAccountsQueryByMonthRes;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.washer.domain.XwDivideAccounts;
import com.ruoyi.washer.service.IXwDivideAccountsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分账处理Controller
 * 
 * @author hawking
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/washer/accounts")
public class XwDivideAccountsController extends BaseController
{
    @Autowired
    private IXwDivideAccountsService xwDivideAccountsService;

    /**
     * 查询分账处理列表
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:list')")
    @GetMapping("/list")
    public TableDataInfo list(XwDivideAccounts xwDivideAccounts)
    {
        startPage();
        List<XwDivideAccounts> list = xwDivideAccountsService.selectXwDivideAccountsList(xwDivideAccounts);
        return getDataTable(list);
    }

    /**
     * 查询分账处理列表
     */
//    @PreAuthorize("@ss.hasPermi('washer:accounts:list')")
    @Anonymous
    @GetMapping("/queryByMonth")
    public TableDataInfo queryByMonth(DivideAccountsQueryByMonthReq divideAccountsQueryByMonthReq)
    {
        startPage();
        List<DivideAccountsQueryByMonthRes> list = xwDivideAccountsService.queryByMonth(divideAccountsQueryByMonthReq);
        return getDataTable(list);
    }

    /**
     * 导出分账处理列表
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:export')")
    @Log(title = "分账处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XwDivideAccounts xwDivideAccounts)
    {
        List<XwDivideAccounts> list = xwDivideAccountsService.selectXwDivideAccountsList(xwDivideAccounts);
        ExcelUtil<XwDivideAccounts> util = new ExcelUtil<XwDivideAccounts>(XwDivideAccounts.class);
        util.exportExcel(response, list, "分账处理数据");
    }

    /**
     * 获取分账处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:query')")
    @GetMapping(value = "/{divideAccountsId}")
    public AjaxResult getInfo(@PathVariable("divideAccountsId") Long divideAccountsId)
    {
        return success(xwDivideAccountsService.selectXwDivideAccountsByDivideAccountsId(divideAccountsId));
    }

    /**
     * 新增分账处理
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:add')")
    @Log(title = "分账处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XwDivideAccounts xwDivideAccounts)
    {
        return toAjax(xwDivideAccountsService.insertXwDivideAccounts(xwDivideAccounts));
    }

    /**
     * 修改分账处理
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:edit')")
    @Log(title = "分账处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XwDivideAccounts xwDivideAccounts)
    {
        return toAjax(xwDivideAccountsService.updateXwDivideAccounts(xwDivideAccounts));
    }

    /**
     * 删除分账处理
     */
    @PreAuthorize("@ss.hasPermi('washer:accounts:remove')")
    @Log(title = "分账处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{divideAccountsIds}")
    public AjaxResult remove(@PathVariable Long[] divideAccountsIds)
    {
        return toAjax(xwDivideAccountsService.deleteXwDivideAccountsByDivideAccountsIds(divideAccountsIds));
    }
}
